//进行大小的比较求最大值
class Array<E extends Comparable<E>> {
    public E retMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
//            if(max < array[i]) {
//                //我们不知道E是什么类型的，所以当E执行擦除机制后会变成Object类，
//                //而Object是引用类型对于引用类型的比较用Comparable接口
//                max = array[i];
//            }
        }
        return max;
    }
}

class Array2 {
    public <E extends Comparable<E>>E retMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Array3 {
    public static <E extends Comparable<E>>E retMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test2 {
    public static void main(String[] args) {
        Integer[] array = {1,3,8,9,15,30,12};

        int max = Array3.retMax(array);

        System.out.println(max);
    }
    public static void main2(String[] args) {
        Array2 arr = new Array2();

        Integer[] array = {1,3,8,9,15,30,12};

        int max = arr.retMax(array);
        //int max = arr.<Integer>retMax(array);
        System.out.println(max);
    }
    public static void main1(String[] args) {
        Integer[] array = {1,3,8,9,15,30,12};

        Array<Integer> arr = new Array<>();

        int max = arr.retMax(array);

        System.out.println(max);
    }
}
